﻿using System;
using MvcContrib.FluentHtml;
using NUnit.Framework;
using System.Web.Mvc;
using ProjetoComperio.Presentation.Web.GlobalResources.HtmlHelper;

namespace ProjetoComperio.Test.WebUI.GlobalResources.HtmlHelper
{
    [TestFixture]
    public class FormHTMLHelperTest
    {
        private ModelViewPage<MyClass> ViewPage;

        [SetUp]
        public void SetUp()
        {
            ViewPage = new ModelViewPage<MyClass>();
        }


        #region TextField and support
        [Test]
        public void TestBlankTextField()
        {
            var expectedValue =
                "<label for='Name'  class='TextBoxLabel2'>Nome</label><div class='div_texbox'><input class='TextBox' id='Name' title='Name' type='text' value='' /><span id='NameMessage' title='NameMessage'></span></div>";
            ModelViewPage<MyClass> viewPage = new ModelViewPage<MyClass>();
            var value = viewPage.TextField(x => x.Name, "Nome").Replace("\"", "'");
            Assert.AreEqual(expectedValue, value);
        }
        [Test]
        public void TestBindHtmlHelperValue_withNullValue()
        {
            ViewPage.ViewData = new ViewDataDictionary<MyClass>();
            Assert.AreEqual("", HtmlHelperExtension.BindHtmlHelperValue(ViewPage, x => x.Name).ToString());
        }

        [Test]
        public void TestBindHtmlHelperValue()
        {
            ViewPage.ViewData = new ViewDataDictionary<MyClass>(new MyClass() { Name = "Higor" });
            Assert.AreEqual("Higor", HtmlHelperExtension.BindHtmlHelperValue(ViewPage, x => x.Name).ToString());
        }

        [Test]
        public void TestSpanMessage()
        {
            Assert.AreEqual("<span id='UserNameMessage' title='UserNameMessage'></span>", HtmlHelperExtension.SpanMessage("UserName"));

        }
        #endregion


    }


    public class MyClass
    {
        public String Name { get; set; }
    }

    public class MyView<T> : MvcContrib.FluentHtml.ModelViewPage<T> where T : MyClass, new()
    {
        public MyView()
        {
            ViewData = new ViewDataDictionary<T>(new T() { Name = "Higor" });
        }
    }
}
